/*
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +  Description: 
  +  Created by 王大宸 on 2020-06-07 21:08
  +  Created with IntelliJ IDEA.
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  */

$(function () {
    /* 搜索框 */
    $.searchTable.searchBtn(loadTable);

    layui.use(['table', 'laypage'], function () {
        table = layui.table;
        layPage = layui.laypage;

        loadTable();

        $('#btn_generate').on('click', function () {
            var checkStatus = table.checkStatus('indexTable');
            var data = checkStatus.data;
            if (data.length == 0) {
                layer.alert("请选择需要的表", {
                    time: 5000,
                    btn: ['确定'],
                    icon: 0
                });
                return false;
            }
            var tableNames = [];
            for (var i = 0; i < data.length; i++) {
                tableNames.push(data[i].tableName);
            }
            location.href = "/generator/code?tables=" + tableNames.join();
        });

    });
});


function loadTable() {
    var name = $("#name").val();
    table.render({
        elem: "#indexTable",
        url: "/page",
        where: {
            tableName: name
        },
        cols: [[
            // {type: 'radio', fixed: 'left'},
            {type: 'checkbox', fixed: 'left'},
            {field: "tableName", title: "表名"},
            {field: "tableComment", title: "表备注"},
            {field: "createTime", title: "创建时间"},
            {fixed: 'right', title: '操作', toolbar: '#toolbarHandle', width: 150, align: "center"}
        ]],
        done: function (res) {
            $.layui.layPage(res.count, page, limit, loadTable);
        }
    });
}